package com.ui;

import java.io.BufferedInputStream;
import java.io.DataInputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;

import com.engine.ReadConfig;

public class SukuBungaThread extends Thread{
	int interval=0;
	public SukuBungaThread(){
		interval = Integer.parseInt(ReadConfig.GET("SUKUBUNGATHREADSLEEP"));
		interval*=1000;
	}
	
	public void run()
	{
		while(!LCDSQ.App.isStop())
		{
			try {
				readSukuBunga();
				Thread.sleep(interval);
			} catch (InterruptedException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		}
	}
	
	@SuppressWarnings("deprecation")
	public void readSukuBunga()
	{
		File file = new File("datas/sukubunga.txt");
	    FileInputStream fis = null;
	    BufferedInputStream bis = null;
	    DataInputStream dis = null;
	    try {
	      fis = new FileInputStream(file);
	      // Here BufferedInputStream is added for fast reading.
	      bis = new BufferedInputStream(fis);
	      dis = new DataInputStream(bis);
	      int idx=0;
	      // dis.available() returns 0 if the file does not have more lines.
	      while (dis.available() != 0) {

	      // this statement reads the line from the file and print it to
	        // the console.
	        String line = dis.readLine();
	        LCDSQ.App.updateSukuBunga(line, idx);
	        idx++;
	      }
	      // dispose all the resources after using them.
	      fis.close();
	      bis.close();
	      dis.close();

	    } catch (FileNotFoundException e) {
	      e.printStackTrace();
	    } catch (IOException e) {
	      e.printStackTrace();
	    }
	}
}
